@echo off
rem Usage MaxsiCopy.bat <FileName> <InputDir> <OutputDir> <SolutionDir> 
rem Paths are without trailing \
rem You need to edit MaxsiEnvironment.bat before calling this batch script.

set FileName=%1%
CALL SET FileName=%%FileName:~1,-1%%
set InputDir=%2%
CALL SET InputDir=%%InputDir:~1,-1%%
set OutputDir=%3%
CALL SET OutputDir=%%OutputDir:~1,-1%%
set SolutionDir=%4%
CALL SET SolutionDir=%%SolutionDir:~1,-1%%

call "%SolutionDir%\MaxsiEnvironment.bat"

if not exist "%MDRoot%" mkdir "%MDRoot%"
if not exist "%MDRoot%" goto RootNotExisting
if not exist "%MDRoot%\%MDBuild%" mkdir "%MDRoot%\%MDBuild%"
if not exist "%MDRoot%\%MDBuild%" goto BuildNotExisting
if not exist "%MDRoot%\%MDBuild%\%OutputDir%" mkdir "%MDRoot%\%MDBuild%\%OutputDir%"
if not exist "%MDRoot%\%MDBuild%\%OutputDir%" goto BinNotExisting

echo Updating: Maxsi Distribution\%MDBuild%\%OutputDir%\%FileName%

@if exist "%SolutionDir%\%InputDir%\%FileName%" copy "%SolutionDir%\%InputDir%\%FileName%" "%MDRoot%\%MDBuild%\%OutputDir%\%FileName%"

goto End

:RootNotExisting
rem Make sure %MDRoot% defined in MaxsiEnvironment.bat is defined and points to the correct location/drive!
rem And that the parent folder exists. 
echo MaxsiCopy.bat Error: Could not create folder '%MDRoot%'!
exit 1

:BuildNotExisting
echo MaxsiCopy.bat Error: Could not create folder '%MDRoot%\%MDBuild%'!
exit 1

:BinNotExisting
echo MaxsiCopy.bat Error: Could not create folder '%MDRoot%\%MDBuild%\%OutputDir%'!
exit 1

:Usage
echo Usage: MaxsiCopy.bat <FileName> <InputDir> <OutputDir> <SolutionDir>
goto End

:End